﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.Data;
using Gizmox.WebGUI.Forms;
namespace VisualWebGuiApplication1
{
    public class GridEX : Gizmox.WebGUI.Forms.ListView
    {
        GridEXFilterControl filterPanel;
        [PropertyTab]
        public GridEXFilterControl FilterPanel
        {
            get { return filterPanel; }
            set { filterPanel = value; }
        }
        bool _totalRow = false;

        [PropertyTab]
        public bool TotalRow
        {
            get { return _totalRow; }
            set { _totalRow = value; }
        }
        //[PropertyTab]
        //public bool ShowFilter
        //{
        //    get { return filterPanel != null; }
        //    set
        //    {
        //        if (value)
        //        {
        //            filterPanel = new GridEXFilterControl();
        //            filterPanel.GridEX = this;
        //            filterPanel.Dock = DockStyle.Top;
        //            filterPanel.Rebind();
        //        }
        //        else filterPanel = null;

        //    }
        //}



        protected override void OnDragDrop(DragEventArgs objDragEventArgs)
        {
            base.OnDragDrop(objDragEventArgs);

        }
        protected override void OnDataBindingComplete(Gizmox.WebGUI.Forms.ListViewBindingCompleteEventArgs e)
        {
            base.OnDataBindingComplete(e);
            this.GridLines = true;
            if (filterPanel != null)
            {
                //it = this.Items.Insert(0, it);
                filterPanel.Rebind();

            }
            if (TotalRow)
            {
                ListViewItem it = new ListViewItem();
                it = this.Items.Add(it);
                DataTable dt = this.DataSource as DataTable;
                if (dt != null)
                {
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        if (dt.Columns[i].DataType == typeof(int)
                            || dt.Columns[i].DataType == typeof(double)
                             || dt.Columns[i].DataType == typeof(decimal))
                        {
                            it.SubItems.Add(dt.Compute("SUM(" + dt.Columns[i].ColumnName + ")", "").ToString());
                        }
                        else it.SubItems.Add("");
                    }
                }
            }

        }

        public void GroupColumn(string columnName, bool isSubtotal)
        {
        }
    }
}
